﻿namespace WinFormsMVC
{
    public class Controller
    {
        public Controller()
            : this(null)
        {
        }

        public Controller(RouteData routeData)
        {
            ViewData = new ViewDataDictionary();
        }

        public ViewDataDictionary ViewData { get; internal set; }
        public RouteData RouteData { get; internal set; }

        protected ViewResult View()
        {
            ViewResult result = new ViewResult();

            result.ViewData = this.ViewData;
            result.RouteData = this.RouteData;

            return result;

            //string controllerName = new StackFrame(1, false).GetMethod().ReflectedType.Name;
            //string actionName = new StackFrame(0, false).GetMethod().Name;

            //Controller controller = GetControllerFromRoute(Route);
            //return (ViewForm)controller.GetType().GetMethod(Route.Action).Invoke(controller, null);
        }

        protected ViewResult View(string controller, string action)
        {
            ViewResult result = new ViewResult();

            result.ViewData = this.ViewData;
            result.RouteData = new RouteData()
            {
                Controller = controller,
                Action = action
            };

            return result;
        }
    }
}
